<?php
session_start();
if(isset($_POST['submit']))
{
  foreach($_POST['qty'] as $key=>$value)
  {
    if( ($value == 0) and (is_numeric($value)))
    {
      unset ($_SESSION['icart'][$key]);
    }
    elseif(($value > 0) and (is_numeric($value)))
    {
      $_SESSION['icart'][$key]=$value;
    }
  }
  header("location:cart.php");
}
if(isset($_POST['payment'])) {
  unset($_SESSION['icart']);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
    <title>World Music</title>
    <link rel="stylesheet" type="text/css" href="style/style.css">
    <link rel="stylesheet" type="text/css" href="style/hdmenu.css">
    <link rel="stylesheet" type="text/css" href="style/loginbox.css">
    <link rel="stylesheet" type="text/css" href="style/preview.css"/>
    <link rel="stylesheet" type="text/css" href="style/wt-rotator.css"/>
    <link rel="stylesheet" type="text/css" href="style/productshow.css"/>
    <link rel="shortcut icon" href="../favicon.ico"> 
    <link rel="stylesheet" type="text/css" href="css/demo.css" />
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <link rel="stylesheet" type="text/css" href="css/jquery.jscrollpane.css" media="all" />
    <script type="text/javascript" src="js/header.js"></script>
    <script type="text/javascript" src="script.js"></script>
    <script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="js/jquery.wt-rotator.min.js"></script>
    <script type="text/javascript" src="js/preview.js"></script>    
    <script type="text/javascript" src="banner_images/swfobject.js"></script>
    <script type="text/javascript" src="js/hover.js"></script>
    <script type="text/javascript" src="js/jquery.easing.1.3.js"></script>
    <script type="text/javascript" src="js/jquery.mousewheel.js"></script>
    <script type="text/javascript" src="js/jquery.contentcarousel.js"></script>
    <script type="text/javascript" src="js/jqueryEasing.js"></script>
    <script type="text/javascript" src="js/scroll.js"></script>
	<link rel="stylesheet" href="style.css" />
</head>
<body>
<div id="contains">
    <div id="head">
      <div id="head_menu">
        <div class="logo">
            <a alt="World Music" title="World Music" href=".">
                <img width="85" alt="Trang chủ" src="images/logo.png">
            </a>
        </div>
        <div class="hdmenu">
          <div class="menu_header">
            <ul id="nav">
              <li><a href=".">Home</a></li>
              <li class="sub"><a href="#">Loa</a>
                <ul>
                  <li><a href="products.php?comp=Sony">Sony</a></li>
                  <li><a href="products.php?comp=Bose">Bose</a></li>
                </ul>
              </li>
              <li class="sub"><a href="#">Máy MP3</a>
                <ul>
                  <li><a href="products.php?comp=Sony">Sony</a></li>
                  <li><a href="products.php?comp=Bose">Bose</a></li>
                </ul>
              </li>
              <li><a href="#">About</a></li>
              <li><a href="#">Contacts</a></li>
            </ul>
          </div>
        </div>   
        <?php
        include 'config.php';
        if(isset($_SESSION['user']) && isset($_SESSION['lName']) && isset($_SESSION['fName']))
        {
          $username=$_SESSION['fName']." ".$_SESSION['lName']; 
        ?>
        <div class="box_login">
           <span>Xin chào:</span>
            <a class='login_txt' href=''><?php echo $username;?></a>
            <a class='login_txt' href='user/logout.php'><span>| Logout</span></a>
            <br class="clear_both">
        </div>
        <?php } else { ?>  
        <div class="box_login">                
          <a onclick="registrybox()" class="bt_register_a" href="javascript:void(0)">Đăng ký</a>
          <a onclick="loginbox()" class="bt_login_a big-link" href="javascript:void(0)">Đăng Nhập</a>
          <br class="clear_both">    
        </div>
        <?php } ?>
        <div class="search_box">
            <form autocomplete="off" name="frmSearch" id="frmSearch" method="post" enctype="multipart/form-data" action ="search.php"> 
                <input type="text" value="Tìm kiếm: Loa,Mp3" class="search_text" id="keyword" name="keyword" onfocus="if (this.value == 'Tìm kiếm: Loa,Mp3') {this.value = ''; }" onblur="if (this.value == '') { this.value = 'Tìm kiếm: Loa,Mp3';}" autocomplete="off">
                <input type="submit" class="search_btn" value="Tìm Kiếm">
            </form>
        </div>
        <br class="clear_both">
      </div>
    </div>

    <!-- Search Result -->
    <ul class="auto-complete-list" style="display: none; height: auto; top: 90px; left: 920.5px; width: 245px;">
    </ul>

    <!-- Login Box -->
    <div id="login-box" class="login">
      <p class="login_title"> Đăng nhập</p>
      <a href="" class="close"><img src="images/close.png" class="img-close" title="Close Window" alt="Close" /></a>
      <form method="POST" class="login-content" action="#">
          <label class="username">
          <span>Tên đăng nhập</span>
          <input id="username" name="username" value="" type="text" autocomplete="on" placeholder="Username">
          <p id="uNo"></p>
          </label>
          <label class="password">
          <span>Mật khẩu</span>
          <input id="password" name="password" value="" type="password" placeholder="Password">
          <p id="pNo"></p>
          </label>
          <p id="rs"></p>
          <button class="button submit-button" type="button" onclick="dangnhap()">Đăng nhập</button>
          <p>
          <a class="forgot" href="#">Quên mật khẩu?</a>
          </p>        
      </form>
    </div>

    <!-- Registry Box -->
    <div id="register-box" class="registry">
      <p class="registry_title"> Đăng ký</p>
      <a href="" class="rclose"><img src="images/close.png" class="img-close" title="Close Window" alt="Close" /></a>
      <form method="POST" class="registry-content" action="#">
          <label class="firstname">
            <span>Tên</span>
            <input id="firstname" name="firstname" value="" type="text" autocomplete="on" placeholder="Tên">
          </label>
          <label class="lastname">
            <span>Họ</span>
            <input id="lastname" name="lastname" value="" type="text" autocomplete="on" placeholder="Họ">
           </label>
          <label class="username">
            <span>Tên đăng nhập</span>
            <input id="username" name="username" value="" type="text" autocomplete="on" placeholder="Tên đăng nhập">
          </label>
          <label class="password">
            <span>Mật khẩu</span>
            <input id="password" name="password" value="" type="password" placeholder="Mật khẩu">
          </label>
          <label class="confirmpassword">
            <span>Xác nhận mật khẩu</span>
            <input id="confirm" name="confirmpassword" value="" type="password" placeholder="Xác nhận mật khẩu">
          </label>
          <label class="gender">
            <span>Bạn là </span>
            <select name="gender">
              <option value="Male" selected>Nam</option>
              <option value="Female">Nữ</option>
            </select>
          </label>
          <label class="email">
            <span>Email</span>
            <input id="email" name="email" value="" type="text" autocomplete="on" placeholder="you@local.com">
          </label>
          <label class="address">
            <span>Địa chỉ</span>
            <input id="address" name="address" value="" type="text" autocomplete="on" placeholder="Ho Chi Minh">
          </label>
          <p id="reg_error"></p>
          <button class="button submit-button" type="button" onclick="dangky()">Đăng ký</button>
          <div>
          <a class="forgot" href="#">Quên mật khẩu?</a>
          </div>        
      </form>
    </div>

    <div class="clear"></div>
    <div class="leftmid">
    <div class="left">
      <img src="images/banner1.png">
    </div>
    <div class="right2">
    <div id="body">
      <div id="comp">
        <a href="products.php?comp=Sony">Sony</a>
        <a href="products.php?comp=Bose">Bose</a>
        <a href="#">SamSung</a>
        <a href="#">Electronic</a>
        <a href="#">Apple</a>
        <a href="#">Yamaha</a>
        <a href="#">LG</a>
        <a href="#">Huyndai</a>
        <a href="#">Uniliver</a>
        <a href="#">Toyota</a>
        <a href="#">Posche</a>
        <a href="#">Suzuki</a>
        <a href="#">Honda</a>
        <a href="#">Inovo</a>
        <a href="#">Sanyo</a>
      </div>
      <div align="center"> 
        <div id="flashcontent">
          <script type="text/javascript"> 
            var so = new SWFObject("banner_images/banner.swf", "mymovie", "960", "220", "11"); 
            so.addParam("menu", "false"); 
            so.write("flashcontent"); 
          </script> 
        </div> 
      </div>  
    	<div class="shopcart">
    		
    		<?php
        if (isset($_SESSION['user'])) {
        $ok=1;
        $total = 0;
        if(isset($_SESSION['icart']))
        {
          foreach($_SESSION['icart'] as $k => $v)
          {
            if(isset($k))
            {
              $ok=2;
            }
          }
        }
        if ($ok == 2)
        {
          echo "<form action='cart.php' method='post'>";
          foreach($_SESSION['icart'] as $key=>$value)
          {
            $item[]=$key;
          }
          $str=implode(",",$item);

          $connect=mysql_connect("localhost","root","") or die("Can not connect database");
          mysql_select_db("worldmusic",$connect);
          $sql="select * from product where pID in ($str)";
          $query=mysql_query($sql);
          echo "<h1 id='conf'>Shop Cart</h1>";
          echo "<a href='index.php'><input type='button' value='< Mua thêm' name='choosemore' class='chon'></a>";
          echo "<table class='tbcart'>";
          echo "<thead class='the'>";
          echo "<tr>";
          echo "<th class='sp'>Sản Phẩm</th>";
          echo "<th class='time'>Thời gian vận chuyển</th>";
          echo "<th class='type'>Hãng</th>";
          echo "<th class='num'>Số Lượng</th>";
          echo "<th class='gia'>Tổng Cộng</th>";
          echo "<th class='delsp'></th>";
          echo "</tr>";
          echo "</thead>";
          echo "<tbody>";
          while($row=mysql_fetch_array($query))
          {
            $i = $row['pCurrentQuantity'];
            $i = $_SESSION['icart'][$row['pID']];
            if ($row['psaleoff'] != 0) {
              $rePrice = ($row['pOriginalPrice']*(100-$row['psaleoff']))/100;
            }
            else {
              $rePrice = $row['pOriginalPrice'];
            }
            echo "<tr>";
            echo "<td class='sp'>$row[pName]</td>";
            echo "<td class='time'>Trong 1 ngày</td>";
            echo "<td class='type'>$row[pManufacture]</td>";
            echo "<td class='num'><select name='qty[$row[pID]]' style='width:50px;'>";
            echo "<option value = '{$_SESSION['icart'][$row['pID']]}' selected='selected'>$i</option>";
            for ($j=1;$j<=5;$j++) {
              echo "<option value = '".$j."'>$j</option>";
            }
            
            echo "</select></td>";
            $tong=$i*$rePrice;
            //echo "<td class='num'><input type='text' name='abc' size='3' value='1' style='width: 50px;'></td>";
            echo "<td id ='gia' class='gia'>$tong</td>";
            echo "<td class='delsp'><a href='delcart.php?productid=$row[pID]'>Xoa Sp</a></td>";
            echo "</tr>";
            //echo "<p align='right'> Gia tien cho mon hang: ". number_format($_SESSION['cart'][$row['id']]*$row['price'],3) ." VND</p>";
            $total += $tong;
          }
          echo "</tbody>";
          echo "</table>";
          echo "<b>Tổng tiền cho các món hàng: <font color='red'>". $total." VND</font></b>";
          echo "<a href='index.php'><input type='submit' value='Cập nhật' name='submit' style='width:100px;margin-left:450px;margin-top:50px;background-color:green;'></a>";
          echo "<input onclick='thanhtoan()' type='submit' value='Thanh toán' name='payment' style='width:100px;margin-left:50px;background-color:blue;'>";
          //echo "<div class='pro' align='right'>";
          
          /*echo "</div>";
          echo "<input type='submit' name='submit' value='Cap Nhat Gio Hang'>";
          echo "<div class='pro' align='center'>";
          echo "<b><a href='index.php'>Mua Sach Tiep</a> - <a href='delcart.php?productid=0'>Xoa Bo Gio Hang</a></b>";
          echo "</div>";  */
        }

      else
      {
        echo "<p class='buy'>Bạn không có món hàng nào trong giỏ hàng<br /><a href='index.php'>Buy Now</a></p>";
      }
    } else echo "<script>alert('You must login to buy product!');window.location.href='index.php';</script>";
    ?>
    <script type="text/javascript">
    function thanhtoan(){
      $(".shopcart").html("<div class='thanks'>Chúng tôi sẽ gọi điện cho bạn trong vòng 24h để xác nhận đơn hàng!Cám ơn và hẹn gặp lại<a href='../ass/delcart.php?productid=0'>Back</a></div>");
      //$(".thanks").css("position")
    }
    </script>
    	</div>
    </div>
    <div class="footer">
      <div class="leftMfooter">
          <div class="leftfooter">
            <div class="footer-title">
              <h2> Thông tin liên lạc </h2>
            </div> 
            <div class="contentleft">
              <p class="p1title">Hotline bán hàng : </p>
              <ul>
                <li>
                  Hotline - HN :
                  <strong>098.8888.465 - 094.8888.196</strong>
                </li>
                <li>
                  Hotline - HCM :
                  <strong>098.8888.162 - 090.2121.288</strong>
                  <ul style="list-style: circle outside none;">
                    <li>669 Lê Hồng Phong - Quận 10</li>
                    <li>465 Võ Văn Tần - Quận 3</li>
                    <li>165 Nguyễn Thái Học - Quận 1</li>
                    <li>45 Trần Quang Khải - Quận 1</li>
                  </ul>
                </li>
              </ul>
              <p class="p2title"> Chăm sóc khách hàng :</p>
              <ul>
                <li>HN: 094.8888.162</li>
                <li>HCM: 098.8888.465</li>
                <li>
                  <a href="mailto:cskh@cellphones.com.vn">Mail: SoundWorld@music.com.vn</a>
                </li>
              </ul>   
            </div>
          </div>
          <div class="midfooter">
            <div class="footer-title">
              <h2> Thông tin hỗ trợ </h2>
            </div> 
            <div class="contentmid">
              <div class="ulleft">
                <ul>
                  <li>
                    <a href="#">Giới thiệu</a>
                  </li>
                  <li>
                    <a href="#">Bảo hành</a>
                  </li>
                  <li>
                    <a href="#">Mua hàng</a>
                  </li>
                  <li>
                    <a href="#">Chuyển hàng</a>
                  </li>
                </ul>
              </div>
              <div class="ulright">
                <ul>
                  <li>
                    <a href="http://cellphones.com.vn/deals-phu-kien-hn">Deals phụ kiện</a>
                  </li>
                  <li>
                    <a href="http://cellphones.com.vn/smember/dang-ki-ban-may-cu">Bán - Đổi máy cũ</a>
                  </li>
                  <li>
                    <a href="http://cellphones.com.vn/dich-vu-khach-hang-doanh-nghiep">Khách hàng doanh nghiệp</a>
                  </li>
                  <li>
                    <a href="http://cellphones.com.vn/smember/dat-hang-tai-cellphones">Đặt mua hàng không có sẵn</a>
                  </li>
                </ul> 
              </div>
              <div class="box-phone">
                <span class="phone">
                  Tổng đài HN: 19006112
                  <br>
                </span>
                <ul class="support-number">
                  <li>Ấn số 1 để được tư vấn bán hàng online</li>
                  <li>Ấn số 2 để gặp bộ phận bảo hành </li>
                  <li>Ấn số 3 để được gặp bộ phận kỹ thuật</li>
                  <li>Ấn số 4 để gặp cửa hàng 117 Thái Hà</li>
                  <li>Ấn số 5 để gặp cửa hàng 19 Thái Hà</li>
                  <li>Ấn số 6 để gặp cửa hàng 21A Hàng Bài</li>
                  <li>Ấn số 7 để gặp cửa hàng 306 Cầu Giấy</li>
                </ul>
              </div>
            </div>
          </div>
      </div>
      <div class="rightfooter">
        <div class="footer-title">
              <h2> Hệ thống cửa hàng </h2>
        </div> 
        <div class="contentright">
          <ul class="showroom">
            <li>
              <a href="#">306 Cầu Giấy, Q. Cầu Giấy, Hà Nội</a>
            </li>
            <li>
              <a href="#">117 Thái Hà, Đống Đa, Hà Nội</a>
            </li>
            <li>
              <a href="#">19 Thái Hà, Đống Đa, Hà Nội</a>
            </li>
            <li>
              <a href="https://www.google.com/maps/place/21+H%C3%A0ng+B%C3%A0i,+Ho%C3%A0n+Ki%E1%BA%BFm/@21.0237587,105.852853,17z/data=!3m1!4b1!4m2!3m1!1s0x3135abecb225927d:0xe70e66e73ce62582">21A Hàng Bài, Hoàn Kiếm, Hà Nội</a>
            </li>
            <li>
              <a href="#">713 Nguyễn Trãi, Q5, HCM</a>
            </li>
            <li>
              <a href="#">45 Trần Quang Khải, Q1, HCM</a>
            </li>
            <li>
              <a href="#">465 Võ Văn Tần, Q3, HCM</a>
            </li>
            <li>
              <a href="#">165 Nguyễn Thái Học, Q1, HCM </a>
            </li>
            <li>
              <a href="#">669 Lê Hồng Phong, Q10, HCM</a>
            </li>
            <li class="last">( vui lòng bấm để xem bản đồ)</li>
          </ul>
          <p>Giờ mở cửa: 8h30 - 21h30 tất cả các ngày trong tuần</p>
        </div>
      </div>
    </div>
    </div>
    </div>
    <div class="right">
      <img src="images/banner2.png">
    </div>
  </div>

<script>







$(document).ready(function(){ 

  (function($){
    $('.right').advScroll({
      easing:'easeOutBack',
      timer:1000
    });
  })(jQuery);

  (function($){
    $('.left').advScroll({
      easing:'easeOutBack',
      timer:1000
    });
  })(jQuery);
});


</script>

</body>
</html>